        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>CallMatcher class / mock Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="mock" data-type="CallMatcher">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../mock.html">mock</a> &rsaquo; <a href="../mock/CallMatcher.html">CallMatcher</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>CallMatcher</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<p>A <a class="crossref" href="../mock/CallMatcher.html#CallMatcher">CallMatcher</a> is a special matcher used to match method calls (i.e.
a method name and set of arguments). It is not a <code>Matcher</code> like the
unit test <code>Matcher</code>, but instead represents a method name and a
collection of <code>Matcher</code>s, one per argument, that will be applied
to the parameters to decide if the method call is a match.</p>
<pre class="source">
class CallMatcher {
 Matcher nameFilter;
 List&lt;Matcher&gt; argMatchers;

 /**
  * Constructor for [CallMatcher]. [name] can be null to
  * match anything, or a literal [String], a predicate [Function],
  * or a [Matcher]. The various arguments can be scalar values or
  * [Matcher]s.
  */
 CallMatcher([name,
             arg0 = _noArg,
             arg1 = _noArg,
             arg2 = _noArg,
             arg3 = _noArg,
             arg4 = _noArg,
             arg5 = _noArg,
             arg6 = _noArg,
             arg7 = _noArg,
             arg8 = _noArg,
             arg9 = _noArg]) {
   if (name == null) {
     nameFilter = anything;
   } else {
     nameFilter = wrapMatcher(name);
   }
   argMatchers = new List&lt;Matcher&gt;();
   if (identical(arg0, _noArg)) return;
   argMatchers.add(wrapMatcher(arg0));
   if (identical(arg1, _noArg)) return;
   argMatchers.add(wrapMatcher(arg1));
   if (identical(arg2, _noArg)) return;
   argMatchers.add(wrapMatcher(arg2));
   if (identical(arg3, _noArg)) return;
   argMatchers.add(wrapMatcher(arg3));
   if (identical(arg4, _noArg)) return;
   argMatchers.add(wrapMatcher(arg4));
   if (identical(arg5, _noArg)) return;
   argMatchers.add(wrapMatcher(arg5));
   if (identical(arg6, _noArg)) return;
   argMatchers.add(wrapMatcher(arg6));
   if (identical(arg7, _noArg)) return;
   argMatchers.add(wrapMatcher(arg7));
   if (identical(arg8, _noArg)) return;
   argMatchers.add(wrapMatcher(arg8));
   if (identical(arg9, _noArg)) return;
   argMatchers.add(wrapMatcher(arg9));
 }

 /**
  * We keep our behavior specifications in a Map, which is keyed
  * by the [CallMatcher]. To make the keys unique and to get a
  * descriptive value for the [CallMatcher] we have this override
  * of [toString()].
  */
 String toString() {
   Description d = new StringDescription();
   d.addDescriptionOf(nameFilter);
   // If the nameFilter was a simple string - i.e. just a method name -
   // strip the quotes to make this more natural in appearance.
   if (d.toString()[0] == "'") {
     d.replace(d.toString().substring(1, d.toString().length - 1));
   }
   d.add('(');
   for (var i = 0; i &lt; argMatchers.length; i++) {
     if (i &gt; 0) d.add(', ');
     d.addDescriptionOf(argMatchers[i]);
   }
   d.add(')');
   return d.toString();
 }

 /**
  * Given a [method] name and list of [arguments], return true
  * if it matches this [CallMatcher.
  */
 bool matches(String method, List arguments) {
   var matchState = new MatchState();
   if (!nameFilter.matches(method, matchState)) {
     return false;
   }
   var numArgs = (arguments == null) ? 0 : arguments.length;
   if (numArgs &lt; argMatchers.length) {
     throw new Exception("Less arguments than matchers for $method.");
   }
   for (var i = 0; i &lt; argMatchers.length; i++) {
     if (!argMatchers[i].matches(arguments[i], matchState)) {
       return false;
     }
   }
   return true;
 }
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="CallMatcher">
<button class="show-code">Code</button>
new <strong>CallMatcher</strong>([name, arg0 = _noArg, arg1 = _noArg, arg2 = _noArg, arg3 = _noArg, arg4 = _noArg, arg5 = _noArg, arg6 = _noArg, arg7 = _noArg, arg8 = _noArg, arg9 = _noArg]) <a class="anchor-link" href="#CallMatcher"
              title="Permalink to CallMatcher.CallMatcher">#</a></h4>
<div class="doc">
<p>Constructor for <a class="crossref" href="../mock/CallMatcher.html#CallMatcher">CallMatcher</a>. 
<span class="param">name</span> can be null to
match anything, or a literal <code>String</code>, a predicate <code>Function</code>,
or a <code>Matcher</code>. The various arguments can be scalar values or
<code>Matcher</code>s.</p>
<pre class="source">
CallMatcher([name,
           arg0 = _noArg,
           arg1 = _noArg,
           arg2 = _noArg,
           arg3 = _noArg,
           arg4 = _noArg,
           arg5 = _noArg,
           arg6 = _noArg,
           arg7 = _noArg,
           arg8 = _noArg,
           arg9 = _noArg]) {
 if (name == null) {
   nameFilter = anything;
 } else {
   nameFilter = wrapMatcher(name);
 }
 argMatchers = new List&lt;Matcher&gt;();
 if (identical(arg0, _noArg)) return;
 argMatchers.add(wrapMatcher(arg0));
 if (identical(arg1, _noArg)) return;
 argMatchers.add(wrapMatcher(arg1));
 if (identical(arg2, _noArg)) return;
 argMatchers.add(wrapMatcher(arg2));
 if (identical(arg3, _noArg)) return;
 argMatchers.add(wrapMatcher(arg3));
 if (identical(arg4, _noArg)) return;
 argMatchers.add(wrapMatcher(arg4));
 if (identical(arg5, _noArg)) return;
 argMatchers.add(wrapMatcher(arg5));
 if (identical(arg6, _noArg)) return;
 argMatchers.add(wrapMatcher(arg6));
 if (identical(arg7, _noArg)) return;
 argMatchers.add(wrapMatcher(arg7));
 if (identical(arg8, _noArg)) return;
 argMatchers.add(wrapMatcher(arg8));
 if (identical(arg9, _noArg)) return;
 argMatchers.add(wrapMatcher(arg9));
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="argMatchers">
<button class="show-code">Code</button>
List&lt;<a href="../matcher/Matcher.html">Matcher</a>&gt;         <strong>argMatchers</strong> <a class="anchor-link"
            href="#argMatchers"
            title="Permalink to CallMatcher.argMatchers">#</a>
        </h4>
        <div class="doc">
<pre class="source">
argMatchers
</pre>
</div>
</div>
<div class="field"><h4 id="nameFilter">
<button class="show-code">Code</button>
<a href="../matcher/Matcher.html">Matcher</a>         <strong>nameFilter</strong> <a class="anchor-link"
            href="#nameFilter"
            title="Permalink to CallMatcher.nameFilter">#</a>
        </h4>
        <div class="doc">
<pre class="source">
nameFilter
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="matches">
<button class="show-code">Code</button>
bool <strong>matches</strong>(String method, List arguments) <a class="anchor-link" href="#matches"
              title="Permalink to CallMatcher.matches">#</a></h4>
<div class="doc">
<p>Given a 
<span class="param">method</span> name and list of 
<span class="param">arguments</span>, return true
if it matches this [CallMatcher.</p>
<pre class="source">
bool matches(String method, List arguments) {
 var matchState = new MatchState();
 if (!nameFilter.matches(method, matchState)) {
   return false;
 }
 var numArgs = (arguments == null) ? 0 : arguments.length;
 if (numArgs &lt; argMatchers.length) {
   throw new Exception("Less arguments than matchers for $method.");
 }
 for (var i = 0; i &lt; argMatchers.length; i++) {
   if (!argMatchers[i].matches(arguments[i], matchState)) {
     return false;
   }
 }
 return true;
}
</pre>
</div>
</div>
<div class="method"><h4 id="toString">
<button class="show-code">Code</button>
String <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to CallMatcher.toString">#</a></h4>
<div class="doc">
<p>We keep our behavior specifications in a Map, which is keyed
by the <a class="crossref" href="../mock/CallMatcher.html#CallMatcher">CallMatcher</a>. To make the keys unique and to get a
descriptive value for the <a class="crossref" href="../mock/CallMatcher.html#CallMatcher">CallMatcher</a> we have this override
of <code>toString()</code>.</p>
<pre class="source">
String toString() {
 Description d = new StringDescription();
 d.addDescriptionOf(nameFilter);
 // If the nameFilter was a simple string - i.e. just a method name -
 // strip the quotes to make this more natural in appearance.
 if (d.toString()[0] == "'") {
   d.replace(d.toString().substring(1, d.toString().length - 1));
 }
 d.add('(');
 for (var i = 0; i &lt; argMatchers.length; i++) {
   if (i &gt; 0) d.add(', ');
   d.addDescriptionOf(argMatchers[i]);
 }
 d.add(')');
 return d.toString();
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
